﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Common;
using WinnerCMS.BLL;
using WinnerCMS.Model.Attribute;
using WinnerCMS.Model.Enum;

#endregion

namespace WinnerCMS.WebUI.Admin.Category
{
    [Access("256003")]
    public partial class Attribute : Page
    {
        private readonly CategoryManage _myBLL = new CategoryManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            this._myBLL.BindDDL(this.lblCategory, BindOption.NoLink, null, null);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            /*
             TemplateFileName
CategoryIntro
CategoryPic
CategoryDescription
CategoryKeyWord
ContentAdmin
CategoryAdmin
OpenGrade
EnableContribute
EnableComment
UrlRewrite
FilePostfix
FilePrefix
URLStyle
CategoryFilePostfix
CategoryFilePrefix
CategoryURLStyle

             */

            var Selected = new List<bool>();
            var Values = new List<object>();

            Selected.Add(this.cbkTemplateFileName.Checked);
            Values.Add(this.txtTemplateFileName.Text);

            Selected.Add(this.cbkCategoryIntro.Checked);
            Values.Add(this.txtCategoryIntro.Text);

            Selected.Add(this.cbkCategoryPic.Checked);
            Values.Add(this.txtCategoryPic.Text);

            Selected.Add(this.cbkCategoryDescription.Checked);
            Values.Add(this.txtCategoryDescription.Text);

            Selected.Add(this.cbkCategoryKeyWord.Checked);
            Values.Add(this.txtCategoryKeyWord.Text);

            Selected.Add(this.cbkContentAdmin.Checked);
            Values.Add(this.UC_AdminSelect1.btnSelectAdmin.Text);

            Selected.Add(this.cbkCategoryAdmin.Checked);
            Values.Add(this.UC_AdminSelect2.btnSelectAdmin.Text);

            Selected.Add(this.cbkOpenGrade.Checked);
            Values.Add(int.Parse(this.RBL_OpenGrade.SelectedValue));

            Selected.Add(this.cbkEnableContribute.Checked);
            Values.Add(int.Parse(this.RBL_EnableContribute.SelectedValue));

            Selected.Add(this.cbkEnableComment.Checked);
            Values.Add(int.Parse(this.RBL_EnableComment.SelectedValue));

            Selected.Add(this.cbkUrlRewrite.Checked);
            Values.Add(int.Parse(this.RBL_UrlRewrite.SelectedValue));

            Selected.Add(this.cbkFilePostfix.Checked);
            Values.Add(this.txtFilePostfix.Text);

            Selected.Add(this.cbkFilePrefix.Checked);
            Values.Add(this.txtFilePrefix.Text);

            Selected.Add(this.cbkURLStyle.Checked);
            Values.Add(int.Parse(this.RBL_URLStyle.SelectedValue));

            Selected.Add(this.cbkCategoryFilePostfix.Checked);
            Values.Add(this.txtCategoryFilePostfix.Text);

            Selected.Add(this.cbkCategoryFilePrefix.Checked);
            Values.Add(this.txtCategoryFilePrefix.Text);

            Selected.Add(this.cbkCategoryURLStyle.Checked);
            Values.Add(int.Parse(this.rblCategoryURLStyle.SelectedValue));

            var IDs = new List<int>();
            foreach (ListItem li in this.lblCategory.Items)
            {
                if (li.Selected)
                    IDs.Add(int.Parse(li.Value));
            }

            var res = this._myBLL.BatchUpData(Selected, Values, IDs);

            if (string.IsNullOrEmpty(res.Errors))
            {
                MsgBox.Message("操作成功！", this);
            }
            else
            {
                MsgBox.Message(res.Errors, this);
            }
        }
    }
}